package com.jidecai.pro.subview;


import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;

import com.jidecai.pro.view.ScrollLayout;
import com.jidecai.pro.view.ScrollLayout.OnScreenChangeListener;

public abstract class AbstractPageControlView extends LinearLayout {
	
	protected int pageCount;
	private static int KEY_BIND = 999;
	protected ScrollLayout scrollViewGroup;
	
	public void bindScrollViewGroup(ScrollLayout scrollViewGroup) {
		this.scrollViewGroup = scrollViewGroup;
		KEY_BIND++;
		this.pageCount=scrollViewGroup.getChildCount();
		generatePageControl(scrollViewGroup.getCurrentScreenIndex(),pageCount);
		scrollViewGroup.addOnScreenChangeListener(KEY_BIND,new OnScreenChangeListener() {
			@Override
			public void onScreenChange(int currentIndex) {
				generatePageControl(currentIndex,pageCount);
			}
		});
	}
	
	public void unBindScrollViewGroup(ScrollLayout scrollViewGroup){
		scrollViewGroup.removeScreenChangeListener(KEY_BIND);
	}

	public AbstractPageControlView(Context context) {
		super(context);
	}
	
	public AbstractPageControlView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	
	public ScrollLayout getScrollLayout(){
		return scrollViewGroup;
	}
	
	public int getPageCount(){
		return pageCount;
	}

	protected abstract void generatePageControl(int currentIndex,int size);
}
